package com.base.user.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.user.dao.BlackFriendsDAO;
import com.base.user.entity.BlackFriends;
import com.base.user.service.BlackFriendsService;
import com.base.user.service.FriendsService;

import cn.mysteel.util.ObjectUtils;

@Service("blackFriendsService")
public class BlackFriendsServiceImpl implements BlackFriendsService
{
	@Autowired
	private FriendsService friendsService;
	@Autowired
	private BlackFriendsDAO blackFriendsDaO;

	@Override
	public void intoBlack(long memberId, long friend_id)
	{
		friendsService.deleteFriends (memberId ,friend_id);
		
		Map<String, Object> params = new HashMap<String,Object>();
		params.put ("memberId" ,memberId);
		params.put ("friend_id" ,friend_id);
		
		BlackFriends bf = blackFriendsDaO.getByF_IdAndM_id (params);
		
		if(ObjectUtils.isNull (bf))
		{
			BlackFriends blackFriends = new BlackFriends ();
			blackFriends.setCreateTime (System.currentTimeMillis ());
			blackFriends.setFriend_id (friend_id);
			blackFriends.setMemberId (memberId);
			
			blackFriendsDaO.save (blackFriends);
		}
	}

	@Override
	public void outBlack(long memberId, long friend_id)
	{
		
		
		
		Map<String, Object> params = new HashMap<String,Object>();
		params.put ("memberId" ,memberId);
		params.put ("friend_id" ,friend_id);
		
		blackFriendsDaO.deleteByF_IdAndM_id (params); 
	}

	@Override
	public List<BlackFriends> queryBlackFriends(long memberId)
	{
		
		return blackFriendsDaO.queryByMemberId (memberId);
	}

	@Override
	public boolean isBlack(long memberId, long friend_id)
	{
		Map<String, Object> params = new HashMap<String,Object>();
		params.put ("memberId" ,memberId);
		params.put ("friend_id" ,friend_id);
		
		BlackFriends bf = blackFriendsDaO.getByF_IdAndM_id (params);
		
		if(ObjectUtils.notNull (bf))
		{
			
			return true;
		}
		
		return false;
	}

	@Override
	public long getBlackNum(long memberId)
	{
		List<BlackFriends> list = blackFriendsDaO.queryByMemberId (memberId);
		
		long num = 0L;
		if(ObjectUtils.notEmpty (list))
		{
			num = list.size ();
		}
		
		return num ;
	}
}
